import { createStore } from 'vuex'
export default createStore({
  state: window.localStorage.getItem("cityinfo") ?
    {
      choseCityInfo: JSON.parse(window.localStorage.getItem("cityinfo") || '{}')
    } : {
      // 选择城市信息
      choseCityInfo: {
        id: "440300",
        name: "广州"
      }
    },
  mutations: {
    // 选择一个城市
    MSetChoseCity(state: { choseCityInfo: any; }, cityInfo: any) {
      // 刷新页面不丢失数据
      window.localStorage.setItem("cityinfo", JSON.stringify(cityInfo))
      state.choseCityInfo = cityInfo;
    }
  },
  actions: {
    ASetChoseCity(context: { commit: (arg0: string, arg1: any) => void; }, cityInfo: any) {
      context.commit("MSetChoseCity", cityInfo)
    }
  }
})